package 普通数组;

/**
 * @author tmh
 * @date 2024/11/26 22:12
 * @description
 */
public class T53最大子数组和 {
    public int maxSubArray(int[] nums) {
        int sum = 0;
        int maxSum = nums[0];
        for (int num : nums) {
            //更新sum  这个sum就是表示前面连续数字的最大和
            sum = Math.max(num, sum + num);
            //更新maxSum  maxSum来维持全局最大和
            maxSum = Math.max(maxSum, sum);
        }
        return maxSum;
    }
}
